package com.wonyesoft.wuliu.acticity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TextView;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.wonyesoft.wuliu.AppContent;
import com.wonyesoft.wuliu.R;
import com.wonyesoft.wuliu.acticity.base.BaseActivity;
import com.wonyesoft.wuliu.acticity.utils.HttpUtilsEx;
import com.wonyesoft.wuliu.api.GagApi;
import com.wonyesoft.wuliu.vo.JsonRequest;
import com.wonyesoft.wuliu.vo.JsonResponse;
import com.wonyesoft.wuliu.vo.State;

public class MyOrderListSSActivity extends BaseActivity implements
		OnClickListener {

	private TabHost mTabHost;
	private RadioGroup mRadioGroup;
	private TextView title, head_right;
	private ImageView head_left;

	private ListView mylist;
	private SimpleAdapter adapter;
	private List<Map<String, Object>> list;

	private TextView myorder_content_tab, myorder_content_time,
			myorder_content_mtext, myorder_content_rmb, myorder_content_qitext,
			myorder_content_zhongtext;

	private Gson gson = new Gson();
	private HttpUtils http = new HttpUtils();
	private RequestParams params;

	@SuppressLint("NewApi")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_myorder);
		title = (TextView) findViewById(R.id.head_title);
		head_left = (ImageView) findViewById(R.id.head_left);
		title.setText("订单管理");
		head_left.setOnClickListener(this);
		head_left.setVisibility(0);

//		getOrderList();
		init();

	}  

	private void init() {
		mylist = (ListView) findViewById(R.id.myorder_listview);
		mylist.setDividerHeight(0);

		adapter = new SimpleAdapter(
				MyOrderListSSActivity.this,
				getData(),
				R.layout.activity_myorder_conent,
				new String[] { "myorder_content_tab", "myorder_content_time",
						"myorder_content_mtext", "myorder_content_rmb",
						"myorder_content_qitext", "myorder_content_zhongtext" },
				new int[] { R.id.myorder_content_tab,
						R.id.myorder_content_time, R.id.myorder_content_mtext,
						R.id.myorder_content_rmb, R.id.myorder_content_qitext,
						R.id.myorder_content_zhongtext });

		mylist.setAdapter(adapter);

		myorder_content_tab = (TextView) findViewById(R.id.myorder_content_tab);
		myorder_content_time = (TextView) findViewById(R.id.myorder_content_time);
		myorder_content_mtext = (TextView) findViewById(R.id.myorder_content_mtext);
		myorder_content_rmb = (TextView) findViewById(R.id.myorder_content_rmb);
		myorder_content_qitext = (TextView) findViewById(R.id.myorder_content_qitext);
		myorder_content_zhongtext = (TextView) findViewById(R.id.myorder_content_zhongtext);

	}

	private List<Map<String, Object>> getData() {
		list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("myorder_content_tab", "我是标题1,不要爱上我");
		map.put("myorder_content_time", "18:19");
		map.put("myorder_content_mtext", "5.3km");
		map.put("myorder_content_rmb", "¥860");
		map.put("myorder_content_qitext", "重庆市永川区宏声广场.........");
		map.put("myorder_content_zhongtext", "重庆市巴南区四公里春晖小区8栋18-3");
		list.add(map);

		Map<String, Object> map1 = new HashMap<String, Object>();
		map1.put("myorder_content_tab", "我是标题2,不要爱上我");
		map1.put("myorder_content_time", "15:4");
		map1.put("myorder_content_mtext", "4.1km");
		map1.put("myorder_content_rmb", "¥120");
		map1.put("myorder_content_qitext", "重庆市永川区茶山竹海");
		map1.put("myorder_content_zhongtext", "重庆市江北区洋河一路");
		list.add(map1);
		return list;
	}

	private void getOrderList() {
		Map<String, Object> dataMap = new HashMap<String, Object>();
		dataMap.put("getOrderList", 1 + "");
		JsonRequest jr = JsonRequest.getInit();
		jr.setData(dataMap);
		String json = gson.toJson(jr);
		params = new RequestParams();
		System.out.println(json);
		params.addBodyParameter("jsonParam", json);
		http.configCookieStore(AppContent.getPreferencesCookieStore());
		System.out.println(AppContent.getPreferencesCookieStore().getCookie("JSESSIONID"));
		http.send(HttpRequest.HttpMethod.POST, GagApi.QueryOnlineOrder, params,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						Gson gson2 = new Gson();
						JsonResponse jrs = gson2.fromJson(responseInfo.result,
								JsonResponse.class);
						System.out.println(responseInfo.result);
						State state = jrs.getState();

						if (state.getCode().equals(State.SUCEECCODE)) {
							System.out.println(state.getMsg());
							openActivity(UserLoginActivity.class);
							finish();
						} else
							// ToastUtils.showLong(state.getMsg());

							System.out.println(state.getMsg());

					}

					@Override
					public void onFailure(HttpException error, String msg) {
						// testTextView.setText(error.getExceptionCode() +
						// ":" +
						// msg);
						System.out.println(msg);
					}
				});

	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.head_left:
			finish();
			break;
		default:
			break;
		}
	}

}
